package com.zbkj.front.controller.merchant;

import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;
import com.zbkj.common.model.order.OrderDetail;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.*;
import com.zbkj.common.response.*;
import com.zbkj.common.result.CommonResult;
import com.zbkj.common.vo.LogisticsResultVo;
import com.zbkj.front.service.EmployeeOrderService;
import com.zbkj.service.service.OrderTraceableRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 移动端订单接收器关系管理
 +----------------------------------------------------------------------
 */
@Slf4j
@RestController
@RequestMapping("api/front/employee/order/traceable/record")
@Api(tags = "移动端订单接收器关系管理 - 订单控制器") //配合swagger使用
public class EmployeeOrderTraceableRecordController {

    @Autowired
    private OrderTraceableRecordService orderTraceableRecordService;

    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<OrderTraceableRecordListPageResponse>> getList(@Validated OrderTraceableRecordSearchRequest request, @Validated PageParamRequest pageParamRequest) {
        return CommonResult.success(CommonPage.restPage(orderTraceableRecordService.getMerchantAdminPage(request, pageParamRequest)));
    }

    @LogControllerAnnotation(intoDB = true, methodType = MethodType.UPDATE, description = "移动端订单接收器关系管理 - 绑定接收器到订单")
    @ApiOperation(value = "绑定接收器到订单")
    @RequestMapping(value = "/bind", method = RequestMethod.POST)
    public CommonResult<Object> bind(@RequestBody @Validated OrderReceiverBindRequest request) {
        if (orderTraceableRecordService.receiverBind(request)) {
            return CommonResult.success().setMessage("操作成功");
        }
        return CommonResult.failed().setMessage("操作失败");
    }

    @ApiOperation(value = "解绑接收器")
    @RequestMapping(value = "/unbind", method = RequestMethod.POST)
    public CommonResult<Object> bind(@RequestBody @Validated OrderReceiverUnBindRequest request) {
        if (orderTraceableRecordService.receiverUnBind(request)) {
            return CommonResult.success().setMessage("操作成功");
        }
        return CommonResult.failed().setMessage("操作失败");
    }

}



